package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 112. 路径总和
 * 
 * https://leetcode.cn/problems/path-sum/
 * 
 * @author jie.deng
 *
 */
class Question0112Solution01 {

	public boolean hasPathSum(TreeNode root, int targetSum) {
		if (root == null) {
			return false;
		}
		// 是否存在 根节点到叶子节点 的路径
		if (root.val == targetSum && root.left == null && root.right == null) {
			return true;
		}
		targetSum -= root.val;
		return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
	}

}